import { BaseGraph, IBaseProps, IBoundBox } from './base'

export interface ICircleProps extends IBaseProps {
  radius?: number
  startAngle?: number
  endAngle?: number
  counterclockwise?: boolean
}

/**
 * 圆形
 */
export class Circle extends BaseGraph {
  public radius: number = 10
  public startAngle: number = 0
  public endAngle: number = Math.PI * 2
  public counterclockwise: boolean = true
  constructor(props?: ICircleProps) {
    super(props)
    this.type = 'circle'
    this.radius = props?.radius || this.radius
    this.startAngle = props?.startAngle || this.startAngle
    this.endAngle = props?.endAngle || this.endAngle
    this.counterclockwise = props?.counterclockwise || this.counterclockwise
    this.setPath()
  }
  public setPath() {
    delete this.path
    this.path = new Path2D()
    this.path.arc(0, 0, this.radius, this.startAngle, this.endAngle, this.counterclockwise)
  }
  public drawPath(ctx: CanvasRenderingContext2D): void {
    if (this.isFill) ctx.fill(this.path)
    else ctx.stroke(this.path)
  }
  public clone() {
    return new Circle({
      ...this.option,
      ...this.getBaseCloneAttr(),
      radius: this.radius,
      startAngle: this.startAngle,
      endAngle: this.endAngle,
      counterclockwise: this.counterclockwise
    })
  }
  public getBoundBox(): IBoundBox {
    return {
      top: this.y - this.radius,
      bottom: this.y + this.radius,
      left: this.x - this.radius,
      right: this.x + this.radius,
      width: this.radius * 2,
      height: this.radius * 2
    }
  }
}
